package seismosurfer.gui;

import java.awt.Dimension;

import javax.help.CSH.DisplayHelpAfterTracking;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;

import seismosurfer.util.ClientRegistry;

import com.bbn.openmap.gui.OMToolComponent;

/**
 * An extension to OMToolComponent that defines a tool
 * for invoking context-sensitive help.
 *
 */
public class HelpTool extends OMToolComponent {
    
    private static final long serialVersionUID = 6656284528685416668L;

    public final static String defaultKey = "helptool";

    protected String key = defaultKey;

    protected JButton helpButton;

    public HelpTool() {
        super();

        setKey(defaultKey);
        helpButton = createButton("help.gif");
        helpButton.setToolTipText("Get Help");

        add(new JLabel("     "));
        add(helpButton);
        helpButton.addActionListener(new DisplayHelpAfterTracking(
                ClientRegistry.getHelpBroker()));
    }
    
    /**
     * Creates the button that will be added in the toolbar.
     * 
     * @param name the name of the file of this button`s icon.
     * @return a JButton that will be added in the toolbar
     */
    protected JButton createButton(String name) {
        java.net.URL url = this.getClass().getResource(name);
        ImageIcon icon = new ImageIcon(url);
        JButton b = new JButton(icon);
        b.setPreferredSize(new Dimension(icon.getIconWidth() + 7, icon
                .getIconHeight() + 7));

        return b;
    }

}